<?php
namespace Admin\Controller;

use Util\AccessController;

class ISBNAPIController extends AccessController {

    public function BookIndex() {
        $LS = Service('M', 'book');
        $sql = "SELECT ID,ISBN from ts_book where PIC_URL is NULL or PIC_URL='' or TITLE is NULL or TITLE=''";
        $data = $LS->SQL($sql);
        $this->DATA = json_encode($data);
        $this->count = count($data);
        $this->BOOK = 1;
        $this->display('index');
    }

    public function SBookIndex() {
        $LS = Service('M', 'sbook');
        $sql = "SELECT ID,ISBN from ts_sbook where PIC_URL is NULL or PIC_URL='' or TITLE is NULL or TITLE=''";
        $data = $LS->SQL($sql);
        $this->DATA = json_encode($data);
        $this->count = count($data);
        $this->BOOK = 0;
        $this->display('index');

    }

    /*
   * 当当抓取书籍信息
   */
    public function GETDATA() {
        $where['ID'] = $_POST['ID'];
        $save = GetBookToIsbnInDDAPI($_POST['ISBN']);
        if ($save != -2) {
            $LS = $_POST['BOOK'] ? Service('M', 'book') : Service('M', 'sbook');
            $OK = $LS->update($where, $save);
            echo $OK;
        }
        echo 0;
    }

    //到处当当url的xls
    public function export_DD_url() {
        $LS = Service('M', 'book');
        $_GET['ZK'] ? $sql = "SELECT ID,ISBN from ts_book where PIC_URL is NULL or PIC_URL=''" : $sql = "SELECT ID,ISBN from ts_sbook where PIC_URL is NULL or PIC_URL=''";
        $data = $LS->SQL($sql);
        foreach ($data as $k => $v) {
            $data[$k]['DD_URL'] = 'http://search.dangdang.com?key=' . $v['ISBN'] . '&ID=' . $v['ID'];
        }
        export($data, array('ID',
            'ISBN',
            'DD_URL'));
    }

}